package dk.dashboardFP.panels.loggerPanel {
	import dk.dashboardFP.dfpLogger.DFPLogger;
	import dk.dashboardFP.panels.panelElements.AbstractDashboardFPPanel;
	import dk.dashboardFP.panels.subPanels.AbsDashboardFPSubPanel;
	import dk.dashboardFP.panels.subPanels.SubPanelModel;
	import dk.dashboardFP.panels.subPanels.WindowSubPanel;
	import dk.dashboardFP.panels.subPanels.ui.windowSubPanelUI.WindowSubPanelUI;

	/**
	 * @author josef
	 */
	public class FilterWindowSubPanel extends WindowSubPanel {
		private var _doFilterWindowContent : FilterWindowContent;
		private var _o_doLogFilterItems : Object = {};
		private var _oFilterWindowModel : FilterWindowModel;

		public function FilterWindowSubPanel(oDashboardFPPanel : AbstractDashboardFPPanel, sSubPanelPlaneTitle : String) {
			super(oDashboardFPPanel, sSubPanelPlaneTitle);
			setupElements();
		}
		
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// model
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

		override protected function get_oSubPanelModel(oSubPanel : AbsDashboardFPSubPanel) : SubPanelModel {
			return new FilterWindowModel(oSubPanel, this);
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// setup
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		
		private function setupElements() : void {
			
			//:::::::
			// window content 
			_doFilterWindowContent=new FilterWindowContent();
			WindowSubPanelUI(_doSubPanelUI).addWindowContent(_doFilterWindowContent);
			
			//:::::::
			// model 
			_oFilterWindowModel=oSubPanelModel as FilterWindowModel;
		}

		public function evaluateGroup(intGroup:int) : void {
			if (!_o_doLogFilterItems[intGroup]) {
				createNewFilterITem(intGroup);
			}
		}
		
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// create new item
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		
		private function createNewFilterITem(intGroup : int) : void {
			
			var doLogFilterItem:LogFilterItem=new LogFilterItem(DFPLogger.getLogGroupById(intGroup));
			
			_o_doLogFilterItems[intGroup] = doLogFilterItem;
			_doFilterWindowContent.addFilter(doLogFilterItem);
			
			dispatchEvent(new FilterWindowSubPanelEvent(FilterWindowSubPanelEvent.NEW_FILTER, doLogFilterItem));
		}
		
		public function get o_doLogFilterItems() : Object {
			return _o_doLogFilterItems;
		}
	}
}
